package com.xxxx.spring.test.jdkTest;


import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;

public class Proxy1 implements HelloService{

    private InvocationHandler h;

    static Method sayHello;
    static {
        try {
            sayHello = HelloService.class.getMethod("sayHello");
        } catch (NoSuchMethodException e) {
            throw new NoSuchMethodError(e.getMessage());
        }
    }


    protected Proxy1(InvocationHandler h) {
        this.h = h;
    }

    @Override
    public void sayHello() {
        try {
            Object invoke = h.invoke(this, sayHello, new Object[0]);
            System.out.println("方法返回 :" + invoke);
        } catch (RuntimeException | Error e) {
            throw e;
        } catch (Throwable e){
            throw new UndeclaredThrowableException(e);
        }

    }
}
